package com.g2room.myuall.util;

import java.awt.image.BufferedImage;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;

import com.g2room.myuall.util.StringUtil;


public class ImageUtil {

	public static void main(String[] args) {
	}
	
	public static Map<Integer, Integer> getImgWidth(String url) {
		Map<Integer, Integer> widthAndHeight = null;
		if(StringUtil.isEmpty(url)) return widthAndHeight;
		try {
			URL u = new URL(url);
			URLConnection urlconn = u.openConnection();
			urlconn.setConnectTimeout(5000);// 设置连接时间
			urlconn.setReadTimeout(5000);// 设置超时时间
	    	BufferedImage sourceImg =ImageIO.read(urlconn.getInputStream());
	    	
	    	if(null != sourceImg) {
	    		widthAndHeight = new HashMap<Integer, Integer>();
	    		widthAndHeight.put(sourceImg.getWidth(), sourceImg.getHeight());
	    	}
	    } catch (Exception e) {
	    	System.out.println("获取图片错误：" + url);
	    	e.printStackTrace();
	    }
		return widthAndHeight;
	}
}
